package nc.bs.so.m33.maintain.m4c;

import java.util.Map;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.so.m33.enumeration.SquareType;
import nc.vo.so.m33.m4c.entity.SquareOutBVO;
import nc.vo.so.m33.m4c.entity.SquareOutVO;
import nc.vo.so.pub.util.AggVOUtil;
import nc.vo.so.pub.util.biz.SOBusiMDEnum;
import nc.vo.so.pub.util.biz.SOBusiUtil;

















public class UpdateSquare4CFlagBP
{
  public void updateSquareBFlagFor4CPush33(SquareOutVO[] sqvos) {
    String[] bizs = (String[])AggVOUtil.getDistinctHeadFieldArray(sqvos, "cbiztypeid", String.class);
    
//    Map<String, SOBusiMDEnum> map = (new SOBusiUtil()).querySOBusiType(bizs);

    
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.FALSE);
      vo.getParentVO().setBautosquarecost(UFBoolean.FALSE);
      Integer ar = SquareType.SQUARETYPE_ET.getIntegerValue();
      Integer ia = SquareType.SQUARETYPE_REG_DEBIT.getIntegerValue();
      
//      String biz = vo.getParentVO().getCbiztypeid();
//      SOBusiMDEnum sobusitype = (SOBusiMDEnum)map.get(biz);
//      if (SOBusiMDEnum.SOBUSIMDENUM_INVOICEFIRST == sobusitype || SOBusiMDEnum.SOBUSIMDENUM_INVOUTPARALLEL == sobusitype) {
//        
//        ar = SquareType.SQUARETYPE_NULL.getIntegerValue();
//        ia = SquareType.SQUARETYPE_NULL.getIntegerValue();
//      } 
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setFpreartype(ar);
        bvo.setFpreiatype(ia);
      } 
    } 
  }






  
  public void updateSquareBFlagForRm4CPush33(SquareOutVO[] sqvos) {
    String[] bizs = (String[])AggVOUtil.getDistinctHeadFieldArray(sqvos, "cbiztypeid", String.class);
    
    Map<String, SOBusiMDEnum> map = (new SOBusiUtil()).querySOBusiType(bizs);

    
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.FALSE);
      vo.getParentVO().setBautosquarecost(UFBoolean.FALSE);
      Integer ar = SquareType.SQUARETYPE_ET.getIntegerValue();
      Integer ia = SquareType.SQUARETYPE_REG_DEBIT.getIntegerValue();


      
      String biz = vo.getParentVO().getCbiztypeid();
      SOBusiMDEnum sobusitype = (SOBusiMDEnum)map.get(biz);
      if (SOBusiMDEnum.SOBUSIMDENUM_INVOICEFIRST == sobusitype || SOBusiMDEnum.SOBUSIMDENUM_INVOUTPARALLEL == sobusitype) {
        
        ar = SquareType.SQUARETYPE_NULL.getIntegerValue();
        ia = SquareType.SQUARETYPE_NULL.getIntegerValue();
      } 
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setFpreartype(ar);
        bvo.setFpreiatype(ia);
      } 
    } 
  }











  
  public void updateSquareBFlagForAdjustIncome(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.TRUE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setNthisnum(bvo.getNnum());
        bvo.setFpreartype((Integer)SquareType.SQUARETYPE_BALANCEAR.value());
      } 
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquareincome" }, new String[] { "fpreartype" });
  }












  
  public void updateSquareBFlagForAutoARIncome(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.TRUE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setNthisnum(bvo.getNnum());
        bvo.setFpreartype((Integer)SquareType.SQUARETYPE_AR.value());
      } 
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquareincome" }, new String[] { "fpreartype" });
  }












  
  public void updateSquareBFlagForAutoETIncome(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.TRUE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setNthisnum(bvo.getNnum());
        bvo.setFpreartype((Integer)SquareType.SQUARETYPE_ET.value());
      } 
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquareincome" }, new String[] { "fpreartype" });
  }












  
  public void updateSquareBFlagForAutoIACost(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquarecost(UFBoolean.TRUE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setNthisnum(bvo.getNnum());
        bvo.setFpreiatype((Integer)SquareType.SQUARETYPE_IA.value());
      } 
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquarecost" }, new String[] { "fpreiatype" });
  }












  
  public void updateSquareBFlagForAutoIARegister(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquarecost(UFBoolean.TRUE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setNthisnum(bvo.getNnum());
        bvo.setFpreiatype((Integer)SquareType.SQUARETYPE_REG_DEBIT.value());
      } 
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquarecost" }, new String[] { "fpreiatype" });
  }












  
  public void updateSquareBFlagForManualARIncome(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquareincome(UFBoolean.FALSE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setFpreartype((Integer)SquareType.SQUARETYPE_AR.value());
      }
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquareincome" }, new String[] { "fpreartype" });
  }












  
  public void updateSquareBFlagForManualIACost(SquareOutVO[] sqvos) {
    for (SquareOutVO vo : sqvos) {
      vo.getParentVO().setBautosquarecost(UFBoolean.FALSE);
      for (SquareOutBVO bvo : vo.getChildrenVO()) {
        bvo.setFpreiatype((Integer)SquareType.SQUARETYPE_IA.value());
      }
    } 
    
    (new UpdateSquare4CFieldsBP()).updateFields(sqvos, new String[] { "bautosquarecost" }, new String[] { "fpreiatype" });
  }
}
